//
//  Archievements.swift
//  Maze24
//
//  Created by Mars on 2021/1/15.
//

import SwiftUI

struct Screen {
  static let width = UIScreen.main.bounds.size.width
  static let height = UIScreen.main.bounds.size.height
  static let size = UIScreen.main.bounds.size
}

struct Archievements: View {
  @ObservedObject var model: Model
  
  var body: some View {
    VStack(alignment: .center) {
      Image(model.displayBadge1 ? "smile1" : "unveil")
        .resizable()
        .frame(width: Screen.width * 0.5, height: Screen.width * 0.5)
      
      Text("解锁以下 9 个成就后自动解锁该成就")
        .font(.caption2)
        .foregroundColor(Color(UIColor.systemGray2))
      
      buildArchievementGrid()
    }
    .padding(.top, 25)
    .navigationTitle("游戏成就")
  }
  
  func buildArchievementGrid() -> some View {
    VStack(spacing: 0) {
      ForEach(Array(stride(from: 2, to: 11, by: 3)), id: \.self) { i in
        HStack(spacing: 0) {
          Image(model.displayBadge(of: i) ? "smile\(i)": "unveil")
            .resizable()
            .frame(width: (Screen.width - 40) / 3, height: (Screen.width - 40) / 3)
          
          Image(model.displayBadge(of: i + 1) ? "smile\(i + 1)": "unveil")
            .resizable()
            .frame(width: (Screen.width - 40) / 3, height: (Screen.width - 40) / 3)
          
          Image(model.displayBadge(of: i + 2) ? "smile\(i + 2)": "unveil")
            .resizable()
            .frame(width: (Screen.width - 40) / 3, height: (Screen.width - 40) / 3)
        }
      }
      
    }
    .padding(.horizontal, 20)
  }
}

struct Archievements_Previews: PreviewProvider {
    static var previews: some View {
      Archievements(model: Model())
    }
}
